Page({
  data: {
    phone: '',
    code: '',
    password: '',
    confirmPassword: '',
    countdown: 0
  },

  getCode() {
    const { phone } = this.data;
    if (!phone || phone.length !== 11) {
      wx.showToast({ title: '请输入正确的手机号', icon: 'none' });
      return;
    }

    let time = 60;
    this.setData({ countdown: time });

    const timer = setInterval(() => {
      time--;
      if (time <= 0) {
        clearInterval(timer);
        this.setData({ countdown: 0 });
      } else {
        this.setData({ countdown: time });
      }
    }, 1000);

    // 向后端发送验证码请求...
  },

  register() {
    const { password, confirmPassword } = this.data;
    if (password !== confirmPassword) {
      wx.showToast({ title: '两次密码不一致', icon: 'none' });
      return;
    }

    // 提交注册数据到后端
  },

  goToLogin() {
    wx.navigateBack();
  }
});